package com.guli.common.pojo.vo;
/*
 * @Author 罗俊
 * @date 2020/11/2 - 8:51 上午
 *
 */

import com.guli.common.valid.UpdateGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 用户购物车中的商品sku信息
 */
@Data
public class SkuItemVo implements Serializable {

    private static final Long serialVersionUID = 998L;

    /**
     * skuId
     */
    @NotNull(groups = UpdateGroup.class)
    private Long skuId;

    /**
     * spuId
     */
    @Null(groups = UpdateGroup.class)
    private Long spuId;

    /**
     * 商品的属性信息
     * */
    @Null(groups = UpdateGroup.class)
    private List<String> spuAttr;

    /**
     * sku名称
     */
    @Null(groups = UpdateGroup.class)
    private String skuName;

    /**
     * 标题
     */
    @Null(groups = UpdateGroup.class)
    private String skuTitle;

    /**
     * 默认图片
     */
    @Null(groups = UpdateGroup.class)
    private String skuDefaultImg;

    /**
     * 价格
     */
    @Null(groups = UpdateGroup.class)
    private BigDecimal price;

    /**
     * 用户要购买的商品数量
     */
    @Range(min = 1)
    private Integer count;

    /**
     * 总价
     */
    @Null(groups = UpdateGroup.class)
    private BigDecimal totalPrice;

    /**
     * 该商品是否被用户选中
     */
    private Boolean isSelected = true;


    public BigDecimal getTotalPrice() {
        this.totalPrice = this.price.multiply(new BigDecimal(this.count));
        return totalPrice;
    }

    @Override
    public String toString() {
        return "SkuItemVo{" +
                "skuId=" + skuId +
                ", spuId=" + spuId +
                ", spuAttr=" + spuAttr +
                ", skuName='" + skuName + '\'' +
                ", skuTitle='" + skuTitle + '\'' +
                ", skuDefaultImg='" + skuDefaultImg + '\'' +
                ", price=" + price +
                ", count=" + count +
                ", totalPrice=" + totalPrice +
                ", isSelected=" + isSelected +
                '}';
    }
}
